import { EnumSchema } from '#/common';
import { PresetColorEnum } from '@/enums/colorEnum';
import { useI18n } from '@/hooks/web/useI18n';

/** 设备类型枚举 */
export enum DeviceTypeEnum {
  /** 设备 */
  Device = 1,
  /** 设备组 */
  Group = 2,
}

/** 设备类型实体 */
export class DeviceTypeEntity {
  /** 设备类型 */
  DeviceType: DeviceTypeEnum;
  /** 显示描述 */
  Display: string;
  /** 颜色 */
  Color?: PresetColorEnum | string;

  constructor(deviceType: DeviceTypeEnum, color?: PresetColorEnum | string) {
    const { t } = useI18n();
    this.DeviceType = deviceType;
    this.Color = color;
    switch (deviceType) {
      case DeviceTypeEnum.Device:
        // this.Display = '设备';
        this.Display = t('iot.enum.deviceType.device');
        this.Color = this.Color ? this.Color : PresetColorEnum.Blue;
        break;
      case DeviceTypeEnum.Group:
        // this.Display = '设备组';
        this.Display = t('iot.enum.deviceType.group');
        this.Color = this.Color ? this.Color : PresetColorEnum.Green;
        break;
    }
  }
}

//#region 获取设备类型枚举架构
/**
 * 获取设备类型枚举架构
 */
export function getDeviceTypeEnumSchema(enableTag = true): EnumSchema[] {
  const enumSchema: EnumSchema[] = [];
  const entities: DeviceTypeEntity[] = [
    new DeviceTypeEntity(DeviceTypeEnum.Device),
    new DeviceTypeEntity(DeviceTypeEnum.Group),
  ];
  entities.forEach((item) => {
    enumSchema.push({
      key: item.DeviceType as number,
      label: item.Display,
      value: item.DeviceType as number,
      tag: enableTag,
      tagColor: item.Color,
    });
  });
  return enumSchema;
}
//#endregion
